{include file="public/head"}
<style>
    .loginFrom{
        width: 100%;
        margin-top: 3rem;
        padding: .5rem .2rem;
        text-align: center;
    }

    .loginFrom input{
        width: 90%;
        height: 3rem;
        line-height: 3rem;
        outline: none;
        border: none;
        border-bottom: 1px #f0f0f0 solid;
    }

    .login{
        background-color: #FF4000;
        border-radius: .1rem;
        font-weight: 600;
        color:white;
        margin: 2rem 0 1rem 0;
    }

    .operation{
        width: 100%;
        padding: 0rem 1.5rem;
        text-align: center;
    }

</style>
<body>
<header class="aui-header-default aui-header-fixed aui-header-bg">
    <a href="javascript:history.back(-1)" class="aui-header-item">
        <i class="aui-icon aui-icon-back-white"></i>
    </a>
    <div class="aui-header-center aui-header-center-clear">
        <div class="aui-header-center-logo">
            <div class="aui-car-white-Typeface">找回密码</div>
        </div>
    </div>
    <a href="#" class="aui-header-item-icon"   style="min-width:0">
        <i class="aui-icon aui-icon-search"></i>
    </a>
</header>

<div class="aui-content-box">
    <div class="aui-banner-content aui-fixed-top" data-aui-slider>
        <div class="aui-banner-wrapper">
            {volist name="BannerList" id="v"}
            <div class="aui-banner-wrapper-item">
                <a href="#">
                    <img src="{$v.url}">
                </a>
            </div>
            {/volist}
        </div>
        <div class="aui-banner-pagination"></div>
    </div>
    <div class="loginFrom">
        <input type="text" id="username" placeholder="用户名">
        <input type="text" id="phone" placeholder="手机号">
        <input type="password" id="new_password" placeholder="请输入密码">
        <input type="password" id="sure_password" placeholder="请重复输入密码">
        <input type="submit" class="login" id="sub" value="找回密码">
    </div>
    <div class="operation">
        <div><a href="{:url('Open/Login')}">立即登录</a></div>
    </div>
</div>

<script type="text/javascript" src="__STATIC__/User/js/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/User/js/aui.js"></script>
<script>
    $(function () {
        var flag1 = true;
        //发送验证吗
        $("#send").on('click',function(){
            if(flag1) {
                flag1 = false
                var phone = $("#phone").val();

                if(phone == ""){
                    alert('请输入手机号');
                    return false;
                }else if(!(/^1[3456789]\d{9}$/.test(phone))){
                    alert('手机号码格式错误')
                    return false;
                }

                $.ajax({
                    type:"POST",
                    url:"{:url('Open/SendCode')}",
                    data:{
                        phone:phone,
                    },
                    dataType:"json",
                    success:function(data){
                        console.log(data)
                        if(data.status == 1){
                            alert(data.message);
                            var time = 60;
                            var interval = setInterval(function(){
                                time -= 1;
                                $("#send").text(`剩余时间${time}`);
                                if(time == 0){
                                    clearInterval(interval)
                                    $("#send").text('重新发送');
                                    flag1 = true
                                }
                            },1000)
                        }else{
                            alert(data.message);
                        }
                    }
                });
            }
        })

        //会员注册
        $("#sub").on('click',function(){
            var username = $("#username").val();
            var phone = $("#phone").val();
            // var code = $("#code").val();
            var new_password = $("#new_password").val();
            var sure_password = $("#sure_password").val();

            if(username == ""){
                alert('请输入用户名');
                return false;
            }

            if(phone == "") {
                alert('请输入手机号');
                return false;
            }
            // }else if(!(/^1[3456789]\d{9}$/.test(phone))){
            //     alert('手机号码格式错误')
            //     return false;
            // }

            // if(code == ""){
            //     alert('请输入验证码');
            //     return false;
            // }

            if(new_password == ""){
                alert('请输入新密码');
                return false;
            }else if(new_password.length < 6){
                alert('请输入6位及以上新密码');
                return false;
            }

            if(new_password != sure_password){
                alert('两次密码不一致');
                return false;
            }

            $.ajax({
                type:"POST",
                url:"{:url('Open/FindPass')}",
                data:{
                    username:username,
                    phone:phone,
                    // code:code,
                    new_password:new_password,
                },
                dataType: "json",
                success:function(data){
                    if (data.status == 1){
                        alert(data.message);
                        window.location.href="{:url('Open/Login')}";
                    }else{
                        alert(data.message);
                    }
                }
            });
        })
    })

</script>

</body>
</html>